package com.wudd.common.util.locationUtils;

import java.util.ArrayList;
import java.util.List;

import com.wudd.common.enums.CoordinateType;
import com.wudd.common.util.locationUtils.GpsUtil.Gps;
public class CoordinatesUtil {
	/**
     * 坐标系的转换
     * 
     * @param sourcetype
     * @param lat 纬度
     * @param lon 经度
     * @param targettype
     * @return
     */
    public static Gps transformCoordinates(CoordinateType sourcetype, double lat,
                                    double lon, CoordinateType targettype) {
                                if(CoordinateType.BD09.equals(sourcetype) && CoordinateType.WGS84.equals(targettype)) {
                                    return PositionUtil.bd09_To_Gps84(lat, lon);
                                }
                                if(CoordinateType.WGS84.equals(sourcetype) && CoordinateType.BD09.equals(targettype)){
                                    return PositionUtil.gps84_To_Bd09(lat, lon);
                                }
                                if(CoordinateType.GCJ02.equals(sourcetype) && CoordinateType.WGS84.equals(targettype)) {
                                    return PositionUtil.gcj02_To_Gps84_exact(lat, lon);
                                }
                                if(CoordinateType.WGS84.equals(sourcetype) && CoordinateType.GCJ02.equals(targettype)) {
                                    return PositionUtil.gps84_To_Gcj02(lat, lon);
                                }
                                if(CoordinateType.GCJ02.equals(sourcetype) && CoordinateType.BD09.equals(targettype)) {
                                    return PositionUtil.gcj02_To_Bd09(lat, lon);
                                }
                                if(CoordinateType.BD09.equals(sourcetype) && CoordinateType.GCJ02.equals(targettype)) {
                                    return PositionUtil.bd09_To_Gcj02(lat, lon);
                                }
                                return new Gps(lon,lat);
                            }
    /**
     * 
     * 批量坐标系的转化
     * @param sourcetype
     * @param sourceCoordinates
     * @param targettype
     * @return
     */
    public static List<Gps> transformCoordinatesBatch(CoordinateType sourcetype, List<Gps> sourceCoordinates, CoordinateType targettype) {
        List<Gps> result = new ArrayList<Gps>();
        for(Gps item:sourceCoordinates) {
            Gps gps = transformCoordinates(sourcetype,item.getLatitude(),item.getLongitude(),targettype);
            result.add(gps);
        }
        return result;
    }
}
